package cn.classyex.business.hr.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import cn.classyex.business.hr.domain.EmployeeTrain;
import cn.classyex.business.hr.service.IEmployeeTrainService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工培训管理Controller
 * 
 * @author yex
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/hr/employeeTrain")
public class EmployeeTrainController extends BaseController
{
    private String prefix = "hr/employeeTrain";

    @Autowired
    private IEmployeeTrainService employeeTrainService;

    @RequiresPermissions("hr:employeeTrain:view")
    @GetMapping()
    public String employeeTrain()
    {
        return prefix + "/employeeTrain";
    }

    /**
     * 查询员工培训管理列表
     */
    @RequiresPermissions("hr:employeeTrain:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EmployeeTrain employeeTrain)
    {
        startPage();
        List<EmployeeTrain> list = employeeTrainService.selectEmployeeTrainList(employeeTrain);
        return getDataTable(list);
    }

    /**
     * 导出员工培训管理列表
     */
    @RequiresPermissions("hr:employeeTrain:export")
    @Log(title = "员工培训管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EmployeeTrain employeeTrain)
    {
        List<EmployeeTrain> list = employeeTrainService.selectEmployeeTrainList(employeeTrain);
        ExcelUtil<EmployeeTrain> util = new ExcelUtil<EmployeeTrain>(EmployeeTrain.class);
        return util.exportExcel(list, "员工培训管理数据");
    }

    /**
     * 新增员工培训管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工培训管理
     */
    @RequiresPermissions("hr:employeeTrain:add")
    @Log(title = "员工培训管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EmployeeTrain employeeTrain)
    {
        return toAjax(employeeTrainService.insertEmployeeTrain(employeeTrain));
    }

    /**
     * 修改员工培训管理
     */
    @GetMapping("/edit/{employeeTrainId}")
    public String edit(@PathVariable("employeeTrainId") Long employeeTrainId, ModelMap mmap)
    {
        EmployeeTrain employeeTrain = employeeTrainService.selectEmployeeTrainById(employeeTrainId);
        mmap.put("employeeTrain", employeeTrain);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工培训管理
     */
    @RequiresPermissions("hr:employeeTrain:edit")
    @Log(title = "员工培训管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EmployeeTrain employeeTrain)
    {
        return toAjax(employeeTrainService.updateEmployeeTrain(employeeTrain));
    }

    /**
     * 删除员工培训管理
     */
    @RequiresPermissions("hr:employeeTrain:remove")
    @Log(title = "员工培训管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(employeeTrainService.deleteEmployeeTrainByIds(ids));
    }
}
